package com.guobo.shopcart.config;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ResponseResult {

    //接口调用结果，成功true，失败false
    private boolean result;
    //接口返回的数据
    private Object data;

    //错误编码
    private int errorCode;
    //错误说明
    private String msg;

    /**
     * 请求成功
     *
     * @param data
     * @return
     */
    public static ResponseResult success(Object data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(data);
        responseResult.setResult(true);
        return responseResult;
    }

    /**
     * 请求失败
     *
     * @param errorCode
     * @param msg
     * @return
     */
    public static ResponseResult fail(int errorCode, String msg) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(null);
        responseResult.setResult(false);
        responseResult.setErrorCode(errorCode);
        responseResult.setMsg(msg);
        return responseResult;
    }

    /**
     * 请求失败
     *
     * @param errorCode
     * @return
     */
    public static ResponseResult fail(int errorCode) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(null);
        responseResult.setResult(false);
        responseResult.setErrorCode(errorCode);
        responseResult.setMsg(null);
        return responseResult;
    }


    public static ResponseResult fail(String s) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(null);
        responseResult.setResult(false);
        responseResult.setMsg(s);
        return responseResult;
    }
}
